package class_1_8.abstract_test;

import java.util.Arrays;

public class Student implements Comparable<Student>{
    private String name;
    private int age;
    public Student(String name,int age){
        this.name=name;
        this.age=age;
    }
    public String toString(){
        return "Student{name="+name+",age="+age+"}";
    }

    public static void main(String[] args) {
        Student stu1=new Student("蕊蕊",18);
        Student stu2=new Student("小蛙",20);
        Student stu3=new Student("菜菜",22);
        Student[] students={stu1,stu2,stu3};
        //Arrays.sort  按照升序
        Arrays.sort(students);
        System.out.println(Arrays.toString(students));
    }

    @Override
    public int compareTo(Student o) {
        if(this.age==o.age){
            return 0;
        }else if(this.age>o.age){
            return 1;
        }else {
            return -1;
        }
    }
}
